import request from "@/utils/request";

const STRATEGY_BASE_URL = "/ig/domain";

const indicatorDomainAPI = {
  /** 根据数据源Id查询指标域/分组 */
  Select(queryParams?: DomainListParameter) {
    return request<any, DomainListResponse>({
      url: `${STRATEGY_BASE_URL}/select`,
      method: "get",
      params: queryParams,
    });
  },
  /** 根据类型和数据源Id查询指标域/分组 */
  SelectByTypeAndSourceId(data?: DomainTreeListParameter) {
    return request<any, IndicatorList[]>({
      url: `${STRATEGY_BASE_URL}/select/parent/domain`,
      method: "post",
      data: data,
    });
  },
  GroupInsert(data?: DomainGroupInsertParameter) {
    return request<any, any>({
      url: `${STRATEGY_BASE_URL}/group/insert`,
      method: "post",
      data: data,
    });
  },
  SelectDomainTree(data?: DomainGroupInsertParameter) {
    return request<any, DomainGroupsTreeReponse>({
      url: `${STRATEGY_BASE_URL}/select/domain/tree`,
      method: "post",
      data: data,
    });
  },
};

export default indicatorDomainAPI;

export interface DomainListParameter {
  dataSourceId?: number;
}

export interface DomainTreeListParameter {
  domainType?: number;
  dataSourceId?: number;
}

export interface DomainGroupsTreeReponse {
  indicatorList?: IndicatorGroupsTree[];
}

export interface DomainListResponse {
  indicatorList?: IndicatorList[];
  themeList?: ThemeList[];
}

export interface IndicatorGroupsTree {
  id?: number;
  domainName?: string;
  disabled?: boolean;
  indicatorGroups?: IndicatorList[];
  themeDomains?: ThemeList[];
}

export interface IndicatorList {
  id?: number;
  domainName?: string;
  disabled?: boolean;
  children?: IndicatorChildren[];
  indicators?: Indicators[];
}

export interface IndicatorChildren {
  id?: number;
  domainName?: string;
  children?: IndicatorChildren[];
  indicators?: Indicators[];
  disabled?: boolean;
}

export interface Indicators {
  id?: number;
  indicatorName?: string;
}

export interface ThemeList {
  id?: number;
  domainName?: string;
  children?: ThemeList[];
  themeTables?: ThemeTablesList[];
}

export interface ThemeTablesList {
  id?: number;
  tableName?: string;
}

export interface DomainGroupInsertParameter {
  domainName?: string;
  domainDescription?: string;
  domainType?: number;
  dataSourceId?: number;
  dataSourceName?: string;
  parentId?: number;
}
